home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 029a / pdsrt321.zip / QUEUE.C < prev    next >
C/C++ Source or Header  |  1991-02-03  |  1KB  |  36 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #include "queue.h"
  6.  
  7. /****************************************************************************
  8.  *  InitQueue initializes a queue for use by the other queue functions.
  9.  ***************************************************************************/
  10.  
  11.  void
  12. InitQueue (QUE_DEF * Q) {
  13.  
  14.     Q->Head = Q->Current = NULL;
  15.     Q->Count = 0;
  16.     }
  17.  
  18. /****************************************************************************
  19.  *  Enque  creates a queue entry linked to the other entries in FIFO order
  20.  *  and puts the string passed into the queue entry.  It returns a pointer
  21.  *  to the entry created [NULL if there is not enough memory for the entry.
  22.  ***************************************************************************/
  23.  
  24.  QUE_ENTRY      *
  25. Enque (QUE_DEF * Q, void *Body) {
  26.     QUE_ENTRY      *p;
  27.  
  28.     if ((p = malloc(sizeof(QUE_ENTRY))) == NULL) return (NULL);
  29.     p->Next = NULL;
  30.     p->Body = Body;
  31.     if (Q->Head == NULL) Q->Head = p;
  32.     else Q->Current->Next = p;
  33.     Q->Current = p;
  34.     ++Q->Count;
  35.     return (p);
  36.     }